package com.wellsoft.mobileoa.utils.action;

import java.util.HashMap;
import java.util.Map;

import com.wellsoft.mobileoa.utils.BaseAction;
import com.wellsoft.mobileoa.utils.BaseActivity;
import com.wellsoft.mobileoa.utils.BaseView;
import com.wellsoft.mobileoa.utils.SystemConfig;
import com.wellsoft.mobileoa.wsmodel.WSOA_Action;
import com.wellsoft.mobileoa.wsmodel.WSOA_HttpGet_Request;
import com.wellsoft.mobileoa.wsmodel.WSOA_HttpGet_Response;
import com.wmobile.utils.BaseObject;
import com.wmobile.utils.ServiceResponse;

public class ExitAction extends BaseAction {

	public ExitAction(WSOA_Action action, BaseView baseView) {
		this.action = action;
		this.baseView = baseView;
	}

	@Override
	public ServiceResponse excuteAction() {
		
		WSOA_HttpGet_Request request = new WSOA_HttpGet_Request();
		request.setUrl(action.getUrl());
		request.setCookies(SystemConfig.getCookies());

		Map<String, BaseObject> httpRequests = new HashMap<String, BaseObject>();

		httpRequests.put("request", request);
		ServiceResponse httpGetResponse = SystemConfig.getService()
				.Callservice(httpRequests, "WSOA_HttpGet",
						WSOA_HttpGet_Response.class);
		if(!httpGetResponse.getExeFlag()){
			return httpGetResponse;
		}
		WSOA_HttpGet_Response response = (WSOA_HttpGet_Response)httpGetResponse.getResponseData();
		if(response.getExeFlag()==0){
			baseView.getBaseActivity().showMessage(response.getMessage());
			return new ServiceResponse(false, response.getMessage());
		}
		BaseActivity.returnLoginActivity();
		return new ServiceResponse(true);
	}

}
